package phantrang;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import trangchu.UtilDelegate;
import form.DSJ_FormMuaHang;

public class PT_TonKho {

	public Vector<DSJ_FormMuaHang> getListHangHoa(Integer soTrang) throws SQLException
    {
            Vector<DSJ_FormMuaHang> result = new Vector<DSJ_FormMuaHang>();
            Connection con =UtilDelegate.getConnection();
            try
            {
                    CallableStatement cst = con.prepareCall("{call DanhSach_HangHoa(?)}");
//					System.out.println(getsoDoiTac());
                    /*
					if (getsoDoiTac() < soTrang*25||soTrang*25<=0) {
                    	cst.setInt(1, 0);
					}else cst.setInt(1, soTrang);
                    */
					cst.setInt(1, soTrang);
                    ResultSet rs =  cst.executeQuery();

                    while(rs.next())
                    {
                    	DSJ_FormMuaHang varmuahang = new DSJ_FormMuaHang();
                    	varmuahang.setMaSP(rs.getString("MaSP"));
                    	varmuahang.setTenSP(rs.getString("TenSP"));
                    	varmuahang.setKho(rs.getString("TenKho"));
                    	varmuahang.setSoLuong(rs.getString("SoLuong"));
                    	varmuahang.setDonViSP(rs.getString("TenDV"));
                    	varmuahang.setNhomSP(rs.getString("TenNH"));
                        
                        result.add(varmuahang);
                    }

            }
            catch (Exception e)
            {
                    e.printStackTrace();
                    result = null;
            }
            finally
            {
                    UtilDelegate.closeConnection(con);	
                    return result;
            }
    }
    public Integer getsoHangHoa() throws SQLException
    {
    		Integer result = null;
    		Connection con =UtilDelegate.getConnection();
            try
            {
                    
                    CallableStatement soLuongRecod = con.prepareCall("{call SoLuong_HangHoa()}");
                    ResultSet rs1 =  soLuongRecod.executeQuery();
					rs1.next();
//					System.out.println(rs1.getInt(1));
					result = rs1.getInt(1);
            }
            catch (Exception e)
            {
                    e.printStackTrace();
                    result = null;
            }
            finally
            {
                    UtilDelegate.closeConnection(con);	
                    return result;
            }
    }
}
